{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "GCP-AZURE Binary Classification Tutorial Level Beginner -  CLF101.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.4"
    },
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "cdbf230f08134c84ad015ebf697c5a37": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "IntProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_3376089bfa864982a9c2007688faa30e",
            "_dom_classes": [],
            "description": "Processing: ",
            "_model_name": "IntProgressModel",
            "bar_style": "",
            "max": 14,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 14,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_70ed6f091c554c9eb98de199f1a24681"
          }
        },
        "3376089bfa864982a9c2007688faa30e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "70ed6f091c554c9eb98de199f1a24681": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "c1d721acda694b2c8e64bd114a5c2525": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "IntProgressModel",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_3a81f2aa0e494d3b83233cff789afb10",
            "_dom_classes": [],
            "description": "Processing: ",
            "_model_name": "IntProgressModel",
            "bar_style": "",
            "max": 16,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 16,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_977afd7dc03440b4bf967c87ac7a6a03"
          }
        },
        "3a81f2aa0e494d3b83233cff789afb10": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "977afd7dc03440b4bf967c87ac7a6a03": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/amjadraza/pycaret/blob/feature%2Fgcp_zure_integration/tutorials/GCP_AZURE_Binary_Classification_Tutorial_Level_Beginner_CLF101.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "Y57RMM1LEQmR"
      },
      "source": [
        "#  <span style=\"color:orange\">Binary Classification  Tutorial (CLF101) - Level Beginner</span>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LrRweUsz9bSl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "! pip uninstall pycaret\n",
        "!pip install git+https://github.com/amjadraza/pycaret.git@feature/gcp_zure_integration"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3sXuMNuqG6PG",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from pycaret.classification import *"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "lUvE187JEQm3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 224
        },
        "outputId": "884aba35-318a-4a9d-c002-8f89624b7e51"
      },
      "source": [
        "from pycaret.datasets import get_data\n",
        "dataset = get_data('credit')"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>LIMIT_BAL</th>\n",
              "      <th>SEX</th>\n",
              "      <th>EDUCATION</th>\n",
              "      <th>MARRIAGE</th>\n",
              "      <th>AGE</th>\n",
              "      <th>PAY_1</th>\n",
              "      <th>PAY_2</th>\n",
              "      <th>PAY_3</th>\n",
              "      <th>PAY_4</th>\n",
              "      <th>PAY_5</th>\n",
              "      <th>PAY_6</th>\n",
              "      <th>BILL_AMT1</th>\n",
              "      <th>BILL_AMT2</th>\n",
              "      <th>BILL_AMT3</th>\n",
              "      <th>BILL_AMT4</th>\n",
              "      <th>BILL_AMT5</th>\n",
              "      <th>BILL_AMT6</th>\n",
              "      <th>PAY_AMT1</th>\n",
              "      <th>PAY_AMT2</th>\n",
              "      <th>PAY_AMT3</th>\n",
              "      <th>PAY_AMT4</th>\n",
              "      <th>PAY_AMT5</th>\n",
              "      <th>PAY_AMT6</th>\n",
              "      <th>default</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>20000</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>24</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1</td>\n",
              "      <td>-2</td>\n",
              "      <td>-2</td>\n",
              "      <td>3913.0</td>\n",
              "      <td>3102.0</td>\n",
              "      <td>689.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>689.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>90000</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>34</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>29239.0</td>\n",
              "      <td>14027.0</td>\n",
              "      <td>13559.0</td>\n",
              "      <td>14331.0</td>\n",
              "      <td>14948.0</td>\n",
              "      <td>15549.0</td>\n",
              "      <td>1518.0</td>\n",
              "      <td>1500.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>5000.0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>50000</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>37</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>46990.0</td>\n",
              "      <td>48233.0</td>\n",
              "      <td>49291.0</td>\n",
              "      <td>28314.0</td>\n",
              "      <td>28959.0</td>\n",
              "      <td>29547.0</td>\n",
              "      <td>2000.0</td>\n",
              "      <td>2019.0</td>\n",
              "      <td>1200.0</td>\n",
              "      <td>1100.0</td>\n",
              "      <td>1069.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>50000</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>57</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>8617.0</td>\n",
              "      <td>5670.0</td>\n",
              "      <td>35835.0</td>\n",
              "      <td>20940.0</td>\n",
              "      <td>19146.0</td>\n",
              "      <td>19131.0</td>\n",
              "      <td>2000.0</td>\n",
              "      <td>36681.0</td>\n",
              "      <td>10000.0</td>\n",
              "      <td>9000.0</td>\n",
              "      <td>689.0</td>\n",
              "      <td>679.0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>50000</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>37</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>64400.0</td>\n",
              "      <td>57069.0</td>\n",
              "      <td>57608.0</td>\n",
              "      <td>19394.0</td>\n",
              "      <td>19619.0</td>\n",
              "      <td>20024.0</td>\n",
              "      <td>2500.0</td>\n",
              "      <td>1815.0</td>\n",
              "      <td>657.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>800.0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   LIMIT_BAL  SEX  EDUCATION  MARRIAGE  ...  PAY_AMT4  PAY_AMT5  PAY_AMT6  default\n",
              "0      20000    2          2         1  ...       0.0       0.0       0.0        1\n",
              "1      90000    2          2         2  ...    1000.0    1000.0    5000.0        0\n",
              "2      50000    2          2         1  ...    1100.0    1069.0    1000.0        0\n",
              "3      50000    1          2         1  ...    9000.0     689.0     679.0        0\n",
              "4      50000    1          1         2  ...    1000.0    1000.0     800.0        0\n",
              "\n",
              "[5 rows x 24 columns]"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "hXmaL1xFEQnj",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        },
        "outputId": "8279a2f7-7be2-4bbf-862b-6227325f685d"
      },
      "source": [
        "data = dataset.sample(frac=0.95, random_state=786).reset_index(drop=True)\n",
        "data_unseen = dataset.drop(data.index).reset_index(drop=True)\n",
        "\n",
        "print('Data for Modeling: ' + str(data.shape))\n",
        "print('Unseen Data For Predictions: ' + str(data_unseen.shape))"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Data for Modeling: (22800, 24)\n",
            "Unseen Data For Predictions: (1200, 24)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wGCZvn1K0M9p",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "exp_clf101 = setup(data = data, target = 'default', session_id=123) "
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "FGCoUiQpEQpz",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 292,
          "referenced_widgets": [
            "cdbf230f08134c84ad015ebf697c5a37",
            "3376089bfa864982a9c2007688faa30e",
            "70ed6f091c554c9eb98de199f1a24681"
          ]
        },
        "outputId": "a8d60f1a-984d-4105-faa4-ec063367423a"
      },
      "source": [
        "\n",
        "rf = create_model('rf')"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style  type=\"text/css\" >\n",
              "    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col0 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col1 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col2 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col3 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col4 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col5 {\n",
              "            background:  yellow;\n",
              "        }    #T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col6 {\n",
              "            background:  yellow;\n",
              "        }</style><table id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >Accuracy</th>        <th class=\"col_heading level0 col1\" >AUC</th>        <th class=\"col_heading level0 col2\" >Recall</th>        <th class=\"col_heading level0 col3\" >Prec.</th>        <th class=\"col_heading level0 col4\" >F1</th>        <th class=\"col_heading level0 col5\" >Kappa</th>        <th class=\"col_heading level0 col6\" >MCC</th>    </tr></thead><tbody>\n",
              "                <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col0\" class=\"data row0 col0\" >0.8095</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col1\" class=\"data row0 col1\" >0.7531</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col2\" class=\"data row0 col2\" >0.3428</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col3\" class=\"data row0 col3\" >0.6269</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col4\" class=\"data row0 col4\" >0.4432</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col5\" class=\"data row0 col5\" >0.3400</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row0_col6\" class=\"data row0 col6\" >0.3626</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col0\" class=\"data row1 col0\" >0.8127</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col1\" class=\"data row1 col1\" >0.7451</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col2\" class=\"data row1 col2\" >0.3399</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col3\" class=\"data row1 col3\" >0.6452</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col4\" class=\"data row1 col4\" >0.4453</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col5\" class=\"data row1 col5\" >0.3453</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row1_col6\" class=\"data row1 col6\" >0.3710</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col0\" class=\"data row2 col0\" >0.8076</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col1\" class=\"data row2 col1\" >0.7714</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col2\" class=\"data row2 col2\" >0.3258</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col3\" class=\"data row2 col3\" >0.6250</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col4\" class=\"data row2 col4\" >0.4283</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col5\" class=\"data row2 col5\" >0.3262</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row2_col6\" class=\"data row2 col6\" >0.3512</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col0\" class=\"data row3 col0\" >0.7989</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col1\" class=\"data row3 col1\" >0.7185</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col2\" class=\"data row3 col2\" >0.3144</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col3\" class=\"data row3 col3\" >0.5842</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col4\" class=\"data row3 col4\" >0.4088</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col5\" class=\"data row3 col5\" >0.3006</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row3_col6\" class=\"data row3 col6\" >0.3215</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col0\" class=\"data row4 col0\" >0.8051</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col1\" class=\"data row4 col1\" >0.7249</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col2\" class=\"data row4 col2\" >0.3229</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col3\" class=\"data row4 col3\" >0.6129</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col4\" class=\"data row4 col4\" >0.4230</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col5\" class=\"data row4 col5\" >0.3191</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row4_col6\" class=\"data row4 col6\" >0.3428</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row5\" class=\"row_heading level0 row5\" >5</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col0\" class=\"data row5 col0\" >0.8152</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col1\" class=\"data row5 col1\" >0.7324</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col2\" class=\"data row5 col2\" >0.3569</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col3\" class=\"data row5 col3\" >0.6495</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col4\" class=\"data row5 col4\" >0.4607</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col5\" class=\"data row5 col5\" >0.3603</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row5_col6\" class=\"data row5 col6\" >0.3839</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row6\" class=\"row_heading level0 row6\" >6</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col0\" class=\"data row6 col0\" >0.8039</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col1\" class=\"data row6 col1\" >0.7244</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col2\" class=\"data row6 col2\" >0.3371</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col3\" class=\"data row6 col3\" >0.6010</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col4\" class=\"data row6 col4\" >0.4319</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col5\" class=\"data row6 col5\" >0.3246</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row6_col6\" class=\"data row6 col6\" >0.3444</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row7\" class=\"row_heading level0 row7\" >7</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col0\" class=\"data row7 col0\" >0.8158</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col1\" class=\"data row7 col1\" >0.7711</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col2\" class=\"data row7 col2\" >0.3399</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col3\" class=\"data row7 col3\" >0.6630</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col4\" class=\"data row7 col4\" >0.4494</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col5\" class=\"data row7 col5\" >0.3523</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row7_col6\" class=\"data row7 col6\" >0.3807</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row8\" class=\"row_heading level0 row8\" >8</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col0\" class=\"data row8 col0\" >0.8139</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col1\" class=\"data row8 col1\" >0.7183</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col2\" class=\"data row8 col2\" >0.3258</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col3\" class=\"data row8 col3\" >0.6609</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col4\" class=\"data row8 col4\" >0.4364</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col5\" class=\"data row8 col5\" >0.3400</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row8_col6\" class=\"data row8 col6\" >0.3706</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row9\" class=\"row_heading level0 row9\" >9</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col0\" class=\"data row9 col0\" >0.8107</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col1\" class=\"data row9 col1\" >0.7419</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col2\" class=\"data row9 col2\" >0.3569</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col3\" class=\"data row9 col3\" >0.6269</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col4\" class=\"data row9 col4\" >0.4549</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col5\" class=\"data row9 col5\" >0.3506</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row9_col6\" class=\"data row9 col6\" >0.3710</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row10\" class=\"row_heading level0 row10\" >Mean</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col0\" class=\"data row10 col0\" >0.8093</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col1\" class=\"data row10 col1\" >0.7401</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col2\" class=\"data row10 col2\" >0.3363</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col3\" class=\"data row10 col3\" >0.6295</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col4\" class=\"data row10 col4\" >0.4382</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col5\" class=\"data row10 col5\" >0.3359</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row10_col6\" class=\"data row10 col6\" >0.3600</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002level0_row11\" class=\"row_heading level0 row11\" >SD</th>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col0\" class=\"data row11 col0\" >0.0052</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col1\" class=\"data row11 col1\" >0.0190</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col2\" class=\"data row11 col2\" >0.0134</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col3\" class=\"data row11 col3\" >0.0243</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col4\" class=\"data row11 col4\" >0.0149</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col5\" class=\"data row11 col5\" >0.0172</td>\n",
              "                        <td id=\"T_f71708a4_d91f_11ea_b297_0242ac1c0002row11_col6\" class=\"data row11 col6\" >0.0186</td>\n",
              "            </tr>\n",
              "    </tbody></table>"
            ],
            "text/plain": [
              "<pandas.io.formats.style.Styler at 0x7fed028bbac8>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "gmaIfnBMEQrE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 292,
          "referenced_widgets": [
            "c1d721acda694b2c8e64bd114a5c2525",
            "3a81f2aa0e494d3b83233cff789afb10",
            "977afd7dc03440b4bf967c87ac7a6a03"
          ]
        },
        "outputId": "fc41b7bd-af08-4658-eb0b-8ecfc124bfa6"
      },
      "source": [
        "tuned_rf = tune_model(rf)"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<style  type=\"text/css\" >\n",
              "    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col0 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col1 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col2 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col3 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col4 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col5 {\n",
              "            background:  yellow;\n",
              "        }    #T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col6 {\n",
              "            background:  yellow;\n",
              "        }</style><table id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >Accuracy</th>        <th class=\"col_heading level0 col1\" >AUC</th>        <th class=\"col_heading level0 col2\" >Recall</th>        <th class=\"col_heading level0 col3\" >Prec.</th>        <th class=\"col_heading level0 col4\" >F1</th>        <th class=\"col_heading level0 col5\" >Kappa</th>        <th class=\"col_heading level0 col6\" >MCC</th>    </tr></thead><tbody>\n",
              "                <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col0\" class=\"data row0 col0\" >0.8258</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col1\" class=\"data row0 col1\" >0.7863</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col2\" class=\"data row0 col2\" >0.3654</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col3\" class=\"data row0 col3\" >0.7049</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col4\" class=\"data row0 col4\" >0.4813</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col5\" class=\"data row0 col5\" >0.3891</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row0_col6\" class=\"data row0 col6\" >0.4194</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col0\" class=\"data row1 col0\" >0.8227</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col1\" class=\"data row1 col1\" >0.7977</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col2\" class=\"data row1 col2\" >0.3541</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col3\" class=\"data row1 col3\" >0.6944</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col4\" class=\"data row1 col4\" >0.4690</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col5\" class=\"data row1 col5\" >0.3758</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row1_col6\" class=\"data row1 col6\" >0.4066</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col0\" class=\"data row2 col0\" >0.8233</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col1\" class=\"data row2 col1\" >0.8225</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col2\" class=\"data row2 col2\" >0.3853</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col3\" class=\"data row2 col3\" >0.6766</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col4\" class=\"data row2 col4\" >0.4910</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col5\" class=\"data row2 col5\" >0.3937</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row2_col6\" class=\"data row2 col6\" >0.4165</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col0\" class=\"data row3 col0\" >0.8177</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col1\" class=\"data row3 col1\" >0.7713</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col2\" class=\"data row3 col2\" >0.3598</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col3\" class=\"data row3 col3\" >0.6615</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col4\" class=\"data row3 col4\" >0.4661</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col5\" class=\"data row3 col5\" >0.3675</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row3_col6\" class=\"data row3 col6\" >0.3923</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col0\" class=\"data row4 col0\" >0.8227</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col1\" class=\"data row4 col1\" >0.7805</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col2\" class=\"data row4 col2\" >0.3513</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col3\" class=\"data row4 col3\" >0.6966</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col4\" class=\"data row4 col4\" >0.4670</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col5\" class=\"data row4 col5\" >0.3743</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row4_col6\" class=\"data row4 col6\" >0.4059</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row5\" class=\"row_heading level0 row5\" >5</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col0\" class=\"data row5 col0\" >0.8227</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col1\" class=\"data row5 col1\" >0.7955</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col2\" class=\"data row5 col2\" >0.3683</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col3\" class=\"data row5 col3\" >0.6842</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col4\" class=\"data row5 col4\" >0.4788</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col5\" class=\"data row5 col5\" >0.3834</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row5_col6\" class=\"data row5 col6\" >0.4101</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row6\" class=\"row_heading level0 row6\" >6</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col0\" class=\"data row6 col0\" >0.8158</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col1\" class=\"data row6 col1\" >0.7568</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col2\" class=\"data row6 col2\" >0.3371</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col3\" class=\"data row6 col3\" >0.6648</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col4\" class=\"data row6 col4\" >0.4474</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col5\" class=\"data row6 col5\" >0.3507</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row6_col6\" class=\"data row6 col6\" >0.3799</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row7\" class=\"row_heading level0 row7\" >7</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col0\" class=\"data row7 col0\" >0.8377</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col1\" class=\"data row7 col1\" >0.7941</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col2\" class=\"data row7 col2\" >0.3768</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col3\" class=\"data row7 col3\" >0.7733</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col4\" class=\"data row7 col4\" >0.5067</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col5\" class=\"data row7 col5\" >0.4231</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row7_col6\" class=\"data row7 col6\" >0.4623</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row8\" class=\"row_heading level0 row8\" >8</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col0\" class=\"data row8 col0\" >0.8227</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col1\" class=\"data row8 col1\" >0.7671</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col2\" class=\"data row8 col2\" >0.3569</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col3\" class=\"data row8 col3\" >0.6923</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col4\" class=\"data row8 col4\" >0.4710</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col5\" class=\"data row8 col5\" >0.3773</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row8_col6\" class=\"data row8 col6\" >0.4073</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row9\" class=\"row_heading level0 row9\" >9</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col0\" class=\"data row9 col0\" >0.8138</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col1\" class=\"data row9 col1\" >0.7833</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col2\" class=\"data row9 col2\" >0.3654</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col3\" class=\"data row9 col3\" >0.6386</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col4\" class=\"data row9 col4\" >0.4649</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col5\" class=\"data row9 col5\" >0.3621</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row9_col6\" class=\"data row9 col6\" >0.3828</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row10\" class=\"row_heading level0 row10\" >Mean</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col0\" class=\"data row10 col0\" >0.8225</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col1\" class=\"data row10 col1\" >0.7855</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col2\" class=\"data row10 col2\" >0.3620</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col3\" class=\"data row10 col3\" >0.6887</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col4\" class=\"data row10 col4\" >0.4743</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col5\" class=\"data row10 col5\" >0.3797</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row10_col6\" class=\"data row10 col6\" >0.4083</td>\n",
              "            </tr>\n",
              "            <tr>\n",
              "                        <th id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002level0_row11\" class=\"row_heading level0 row11\" >SD</th>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col0\" class=\"data row11 col0\" >0.0062</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col1\" class=\"data row11 col1\" >0.0176</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col2\" class=\"data row11 col2\" >0.0128</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col3\" class=\"data row11 col3\" >0.0339</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col4\" class=\"data row11 col4\" >0.0154</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col5\" class=\"data row11 col5\" >0.0188</td>\n",
              "                        <td id=\"T_1474c3e6_d920_11ea_b297_0242ac1c0002row11_col6\" class=\"data row11 col6\" >0.0220</td>\n",
              "            </tr>\n",
              "    </tbody></table>"
            ],
            "text/plain": [
              "<pandas.io.formats.style.Styler at 0x7fed02937a20>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "nwaZk6oTEQsi",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 80
        },
        "outputId": "c60182d4-b44e-4853-fe5f-02701c885d5e"
      },
      "source": [
        "predict_model(tuned_rf);"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Model</th>\n",
              "      <th>Accuracy</th>\n",
              "      <th>AUC</th>\n",
              "      <th>Recall</th>\n",
              "      <th>Prec.</th>\n",
              "      <th>F1</th>\n",
              "      <th>Kappa</th>\n",
              "      <th>MCC</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Random Forest Classifier</td>\n",
              "      <td>0.8135</td>\n",
              "      <td>0.7563</td>\n",
              "      <td>0.3245</td>\n",
              "      <td>0.6591</td>\n",
              "      <td>0.4349</td>\n",
              "      <td>0.3383</td>\n",
              "      <td>0.3688</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "                      Model  Accuracy     AUC  ...      F1   Kappa     MCC\n",
              "0  Random Forest Classifier    0.8135  0.7563  ...  0.4349  0.3383  0.3688\n",
              "\n",
              "[1 rows x 8 columns]"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "r79BGjIfEQs1"
      },
      "source": [
        "# 12.0 Finalize Model for Deployment"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "_--tO4KGEQs-",
        "colab": {}
      },
      "source": [
        "final_rf = finalize_model(tuned_rf)"
      ],
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "U9W6kXsSEQtQ",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 161
        },
        "outputId": "eb354276-8fe0-476e-e1b5-d5649a4f22c8"
      },
      "source": [
        "#Final Random Forest model parameters for deployment\n",
        "print(final_rf)"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,\n",
            "                       criterion='gini', max_depth=10, max_features='auto',\n",
            "                       max_leaf_nodes=None, max_samples=None,\n",
            "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
            "                       min_samples_leaf=2, min_samples_split=10,\n",
            "                       min_weight_fraction_leaf=0.0, n_estimators=70, n_jobs=-1,\n",
            "                       oob_score=False, random_state=123, verbose=0,\n",
            "                       warm_start=False)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "NJDk3I-EEQtg",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 80
        },
        "outputId": "64d82cb1-c8ff-4440-c977-17e280920e23"
      },
      "source": [
        "predict_model(final_rf);"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Model</th>\n",
              "      <th>Accuracy</th>\n",
              "      <th>AUC</th>\n",
              "      <th>Recall</th>\n",
              "      <th>Prec.</th>\n",
              "      <th>F1</th>\n",
              "      <th>Kappa</th>\n",
              "      <th>MCC</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Random Forest Classifier</td>\n",
              "      <td>0.8345</td>\n",
              "      <td>0.8222</td>\n",
              "      <td>0.3629</td>\n",
              "      <td>0.7657</td>\n",
              "      <td>0.4924</td>\n",
              "      <td>0.4082</td>\n",
              "      <td>0.4489</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "                      Model  Accuracy     AUC  ...      F1   Kappa     MCC\n",
              "0  Random Forest Classifier    0.8345  0.8222  ...  0.4924  0.4082  0.4489\n",
              "\n",
              "[1 rows x 8 columns]"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dWU2Dmdx2UNZ",
        "colab_type": "text"
      },
      "source": [
        "# 13.0 Deploy Model on Microsoft Azure\n",
        "\n",
        "This is the code to deploy model on Microsft azure using `pycaret` functionalities."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PtdFIPJJ0zHX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 287
        },
        "outputId": "6d118b7d-6c29-4f1a-8e4a-3a767dae6f95"
      },
      "source": [
        "! pip install azure-storage-blob\n",
        "\n"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Requirement already satisfied: azure-storage-blob in /usr/local/lib/python3.6/dist-packages (12.3.2)\n",
            "Requirement already satisfied: cryptography>=2.1.4 in /usr/local/lib/python3.6/dist-packages (from azure-storage-blob) (3.0)\n",
            "Requirement already satisfied: msrest>=0.6.10 in /usr/local/lib/python3.6/dist-packages (from azure-storage-blob) (0.6.18)\n",
            "Requirement already satisfied: azure-core<2.0.0,>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from azure-storage-blob) (1.7.0)\n",
            "Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from cryptography>=2.1.4->azure-storage-blob) (1.15.0)\n",
            "Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.6/dist-packages (from cryptography>=2.1.4->azure-storage-blob) (1.14.1)\n",
            "Requirement already satisfied: requests~=2.16 in /usr/local/lib/python3.6/dist-packages (from msrest>=0.6.10->azure-storage-blob) (2.23.0)\n",
            "Requirement already satisfied: requests-oauthlib>=0.5.0 in /usr/local/lib/python3.6/dist-packages (from msrest>=0.6.10->azure-storage-blob) (1.3.0)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from msrest>=0.6.10->azure-storage-blob) (2020.6.20)\n",
            "Requirement already satisfied: isodate>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from msrest>=0.6.10->azure-storage-blob) (0.6.0)\n",
            "Requirement already satisfied: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.1.4->azure-storage-blob) (2.20)\n",
            "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests~=2.16->msrest>=0.6.10->azure-storage-blob) (3.0.4)\n",
            "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests~=2.16->msrest>=0.6.10->azure-storage-blob) (2.10)\n",
            "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests~=2.16->msrest>=0.6.10->azure-storage-blob) (1.24.3)\n",
            "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.5.0->msrest>=0.6.10->azure-storage-blob) (3.1.0)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ImFnwpb52iDl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "## Enter connection string when running in google colab\n",
        "connect_str = '' #@param {type:\"string\"}\n",
        "print(connect_str)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4FolddlO2iTK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#! export AZURE_STORAGE_CONNECTION_STRING=connect_str"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "q_MZPZ4271g3",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "os.environ['AZURE_STORAGE_CONNECTION_STRING']= connect_str"
      ],
      "execution_count": 21,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wz0YIfLb6iVK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "! echo $AZURE_STORAGE_CONNECTION_STRING"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cUOqSvi63m01",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "os.getenv('AZURE_STORAGE_CONNECTION_STRING')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "H3C-nMpF2iZg",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 89
        },
        "outputId": "f6c6dbdb-d0c6-400a-d43c-8ee0342edfa1"
      },
      "source": [
        "authentication = {'container': 'pycaret-cls-101'}\n",
        "model_name = 'rf-clf-101'\n",
        "deploy_model(final_rf, model_name, authentication, platform = 'azure')"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Deploying model to Microsoft Azure\n",
            "\n",
            "Uploading to Azure Storage as blob:\n",
            "\trf-clf-101.pkl\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iuBz98UT2icD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 125
        },
        "outputId": "dddd993d-510f-4ffa-bf89-bfff8ad5f279"
      },
      "source": [
        "authentication = {'container': 'pycaret-cls-101'}\n",
        "model_name = 'rf-clf-101'\n",
        "model_azure = load_model(model_name, \n",
        "               platform = 'azure', \n",
        "               authentication = authentication,\n",
        "               verbose=True)"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Loading model from Microsoft Azure\n",
            "\n",
            "Downloading blob to \n",
            "\trf-clf-101.pkl\n",
            "Blob rf-clf-101.pkl downloaded to rf-clf-101.pkl.\n",
            "Transformation Pipeline and Model Successfully Loaded\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aiP_EiLm2iWk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 125
        },
        "outputId": "8243e67b-79a0-4801-a38e-dfd3fbbf4c82"
      },
      "source": [
        "authentication = {'container': 'pycaret-cls-101'}\n",
        "model_name = 'rf-clf-101'\n",
        "unseen_predictions = predict_model(model_name, data=data_unseen, platform='azure', authentication=authentication, verbose=True)"
      ],
      "execution_count": 29,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Loading model from Microsoft Azure\n",
            "\n",
            "Downloading blob to \n",
            "\trf-clf-101.pkl\n",
            "Blob rf-clf-101.pkl downloaded to rf-clf-101.pkl.\n",
            "Transformation Pipeline and Model Successfully Loaded\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UkX3mtAD2iJH",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 439
        },
        "outputId": "98be3bdd-0064-4da4-e488-234668cd5f40"
      },
      "source": [
        "unseen_predictions"
      ],
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>LIMIT_BAL</th>\n",
              "      <th>SEX</th>\n",
              "      <th>EDUCATION</th>\n",
              "      <th>MARRIAGE</th>\n",
              "      <th>AGE</th>\n",
              "      <th>PAY_1</th>\n",
              "      <th>PAY_2</th>\n",
              "      <th>PAY_3</th>\n",
              "      <th>PAY_4</th>\n",
              "      <th>PAY_5</th>\n",
              "      <th>PAY_6</th>\n",
              "      <th>BILL_AMT1</th>\n",
              "      <th>BILL_AMT2</th>\n",
              "      <th>BILL_AMT3</th>\n",
              "      <th>BILL_AMT4</th>\n",
              "      <th>BILL_AMT5</th>\n",
              "      <th>BILL_AMT6</th>\n",
              "      <th>PAY_AMT1</th>\n",
              "      <th>PAY_AMT2</th>\n",
              "      <th>PAY_AMT3</th>\n",
              "      <th>PAY_AMT4</th>\n",
              "      <th>PAY_AMT5</th>\n",
              "      <th>PAY_AMT6</th>\n",
              "      <th>default</th>\n",
              "      <th>Label</th>\n",
              "      <th>Score</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>50000</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>48</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>48572.0</td>\n",
              "      <td>45067.0</td>\n",
              "      <td>46492.0</td>\n",
              "      <td>47368.0</td>\n",
              "      <td>7988.0</td>\n",
              "      <td>8011.0</td>\n",
              "      <td>2028.0</td>\n",
              "      <td>2453.0</td>\n",
              "      <td>2329.0</td>\n",
              "      <td>431.0</td>\n",
              "      <td>300.0</td>\n",
              "      <td>500.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.1591</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>200000</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>40</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>80468.0</td>\n",
              "      <td>82874.0</td>\n",
              "      <td>84900.0</td>\n",
              "      <td>85758.0</td>\n",
              "      <td>87003.0</td>\n",
              "      <td>89112.0</td>\n",
              "      <td>4200.0</td>\n",
              "      <td>4100.0</td>\n",
              "      <td>3000.0</td>\n",
              "      <td>3400.0</td>\n",
              "      <td>3500.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.7779</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>50000</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>44</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>13112.0</td>\n",
              "      <td>14679.0</td>\n",
              "      <td>15143.0</td>\n",
              "      <td>16892.0</td>\n",
              "      <td>16341.0</td>\n",
              "      <td>15798.0</td>\n",
              "      <td>2100.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>2300.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.6478</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>60000</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>31</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>63201.0</td>\n",
              "      <td>56600.0</td>\n",
              "      <td>54952.0</td>\n",
              "      <td>32094.0</td>\n",
              "      <td>31232.0</td>\n",
              "      <td>30384.0</td>\n",
              "      <td>1132.0</td>\n",
              "      <td>60994.0</td>\n",
              "      <td>1436.0</td>\n",
              "      <td>1047.0</td>\n",
              "      <td>1056.0</td>\n",
              "      <td>1053.0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.5038</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>120000</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>32</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>66551.0</td>\n",
              "      <td>67876.0</td>\n",
              "      <td>69903.0</td>\n",
              "      <td>71446.0</td>\n",
              "      <td>79589.0</td>\n",
              "      <td>81354.0</td>\n",
              "      <td>2429.0</td>\n",
              "      <td>3120.0</td>\n",
              "      <td>3300.0</td>\n",
              "      <td>10000.0</td>\n",
              "      <td>3200.0</td>\n",
              "      <td>3200.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.1394</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1195</th>\n",
              "      <td>80000</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>34</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>72557.0</td>\n",
              "      <td>77708.0</td>\n",
              "      <td>79384.0</td>\n",
              "      <td>77519.0</td>\n",
              "      <td>82607.0</td>\n",
              "      <td>81158.0</td>\n",
              "      <td>7000.0</td>\n",
              "      <td>3500.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>7000.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>4000.0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.7523</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1196</th>\n",
              "      <td>150000</td>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>43</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1683.0</td>\n",
              "      <td>1828.0</td>\n",
              "      <td>3502.0</td>\n",
              "      <td>8979.0</td>\n",
              "      <td>5190.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1837.0</td>\n",
              "      <td>3526.0</td>\n",
              "      <td>8998.0</td>\n",
              "      <td>129.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.1499</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1197</th>\n",
              "      <td>30000</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>2</td>\n",
              "      <td>37</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>2</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>3565.0</td>\n",
              "      <td>3356.0</td>\n",
              "      <td>2758.0</td>\n",
              "      <td>20878.0</td>\n",
              "      <td>20582.0</td>\n",
              "      <td>19357.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>22000.0</td>\n",
              "      <td>4200.0</td>\n",
              "      <td>2000.0</td>\n",
              "      <td>3100.0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.4876</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1198</th>\n",
              "      <td>80000</td>\n",
              "      <td>1</td>\n",
              "      <td>3</td>\n",
              "      <td>1</td>\n",
              "      <td>41</td>\n",
              "      <td>1</td>\n",
              "      <td>-1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>-1</td>\n",
              "      <td>-1645.0</td>\n",
              "      <td>78379.0</td>\n",
              "      <td>76304.0</td>\n",
              "      <td>52774.0</td>\n",
              "      <td>11855.0</td>\n",
              "      <td>48944.0</td>\n",
              "      <td>85900.0</td>\n",
              "      <td>3409.0</td>\n",
              "      <td>1178.0</td>\n",
              "      <td>1926.0</td>\n",
              "      <td>52964.0</td>\n",
              "      <td>1804.0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.2613</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1199</th>\n",
              "      <td>50000</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>46</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>47929.0</td>\n",
              "      <td>48905.0</td>\n",
              "      <td>49764.0</td>\n",
              "      <td>36535.0</td>\n",
              "      <td>32428.0</td>\n",
              "      <td>15313.0</td>\n",
              "      <td>2078.0</td>\n",
              "      <td>1800.0</td>\n",
              "      <td>1430.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1000.0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.1569</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1200 rows × 26 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "      LIMIT_BAL  SEX  EDUCATION  MARRIAGE  ...  PAY_AMT6  default  Label   Score\n",
              "0         50000    2          2         1  ...     500.0        0      0  0.1591\n",
              "1        200000    2          1         1  ...       0.0        1      1  0.7779\n",
              "2         50000    2          3         1  ...       0.0        1      1  0.6478\n",
              "3         60000    2          2         1  ...    1053.0        1      1  0.5038\n",
              "4        120000    2          3         2  ...    3200.0        0      0  0.1394\n",
              "...         ...  ...        ...       ...  ...       ...      ...    ...     ...\n",
              "1195      80000    1          2         2  ...    4000.0        1      1  0.7523\n",
              "1196     150000    1          3         2  ...       0.0        0      0  0.1499\n",
              "1197      30000    1          2         2  ...    3100.0        1      0  0.4876\n",
              "1198      80000    1          3         1  ...    1804.0        1      0  0.2613\n",
              "1199      50000    1          2         1  ...    1000.0        1      0  0.1569\n",
              "\n",
              "[1200 rows x 26 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2CRqugcz2h5a",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0ZxYxszDBqJh",
        "colab_type": "text"
      },
      "source": [
        "# 13.0 Deploy Model on Google Cloud"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "N5qy_gsfB1rA",
        "colab_type": "text"
      },
      "source": [
        "After the model is finalised and you are happy with the model, you can deploy the model on your cloud of choice. In this section, we deploy the model on the google cloud platform. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2eJdBC3EClnW",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import auth\n",
        "auth.authenticate_user()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9L31JPblEPG6",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "! pip install awscli"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "i8xWrcliQCz1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# GCP project name, Change the name based on your own GCP project.\n",
        "CLOUD_PROJECT = 'gcpessentials-rz' # GCP project name\n",
        "bucket_name = 'pycaret-clf101-test1' # bucket name for storage of your model\n",
        "BUCKET = 'gs://' + CLOUD_PROJECT + '-{}'.format(bucket_name)\n",
        "# Set the gcloud consol to $CLOUD_PROJECT Environment Variable for your Desired Project)\n",
        "!gcloud config set project $CLOUD_PROJECT"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fq7-Su1iQuHl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "authentication = {'project': CLOUD_PROJECT, 'bucket' : bucket_name}\n",
        "model_name = 'rf-clf'\n",
        "deploy_model(final_rf, model_name, authentication, platform = 'gcp')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CN0CkUXKRAlc",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "authentication = {'project': CLOUD_PROJECT, 'bucket' : bucket_name}\n",
        "model_name = 'rf-clf'\n",
        "model_gcp = load_model(model_name, \n",
        "               platform = 'gcp', \n",
        "               authentication = authentication,\n",
        "               verbose=True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hlY68MyNbZ8d",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "estimator_ = load_model(model_name, platform='gcp',\n",
        "                                   authentication=authentication,\n",
        "                                   verbose=True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bIMlREBHXTtF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "authentication = {'project': CLOUD_PROJECT, 'bucket' : bucket_name}\n",
        "model_name = 'rf-clf'\n",
        "unseen_predictions = predict_model(model_name, data=data_unseen, platform='gcp', authentication=authentication, verbose=True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CFxn0KJ_ebGz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "unseen_predictions"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8lEM1JyDcB_3",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "authentication"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SGY9ZiecTC1X",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import inspect as i\n",
        "import sys\n",
        "sys.stdout.write(i.getsource(predict_model))\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "hUzc6tXNEQtr"
      },
      "source": [
        "# 13.0 Predict on unseen data"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "dx5vXjChEQtt"
      },
      "source": [
        "The `predict_model()` function is also used to predict on the unseen dataset. The only difference from section 11 above is that this time we will pass the `data_unseen` parameter. `data_unseen` is the variable created at the beginning of the tutorial and contains 5% (1200 samples) of the original dataset which was never exposed to PyCaret. (see section 5 for explanation)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "0y5KWLC6EQtx",
        "colab": {}
      },
      "source": [
        "unseen_predictions = predict_model(final_rf, data=data_unseen)\n",
        "unseen_predictions.head()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "oPYmVpugEQt5"
      },
      "source": [
        "The `Label` and `Score` columns are added onto the `data_unseen` set. Label is the prediction and score is the probability of the prediction. Notice that predicted results are concatenated to the original dataset while all the transformations are automatically performed in the background."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "L__po3sUEQt7"
      },
      "source": [
        "# 14.0 Saving the model"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "1sQPT7jrEQt-"
      },
      "source": [
        "We have now finished the experiment by finalizing the `tuned_rf` model which is now stored in `final_rf` variable. We have also used the model stored in `final_rf` to predict `data_unseen`. This brings us to the end of our experiment, but one question is still to be asked: What happens when you have more new data to predict? Do you have to go through the entire experiment again? The answer is no, PyCaret's inbuilt function `save_model()` allows you to save the model along with entire transformation pipeline for later use."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "ln1YWIXTEQuA",
        "colab": {}
      },
      "source": [
        "save_model(final_rf,'Final RF Model 08Feb2020')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "WE6f48AYEQuR"
      },
      "source": [
        "(TIP : It's always good to use date in the filename when saving models, it's good for version control.)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "Z8OBesfkEQuU"
      },
      "source": [
        "# 15.0 Loading the saved model"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "V2K_WLaaEQuW"
      },
      "source": [
        "To load a saved model at a future date in the same or an alternative environment, we would use PyCaret's `load_model()` function and then easily apply the saved model on new unseen data for prediction."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "Siw_2EIUEQub",
        "colab": {}
      },
      "source": [
        "saved_final_rf = load_model('Final RF Model 08Feb2020')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "1zyi6-Q-EQuq"
      },
      "source": [
        "Once the model is loaded in the environment, you can simply use it to predict on any new data using the same `predict_model()` function. Below we have applied the loaded model to predict the same `data_unseen` that we used in section 13 above."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "HMPO1ka9EQut",
        "colab": {}
      },
      "source": [
        "new_prediction = predict_model(saved_final_rf, data=data_unseen)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab_type": "code",
        "id": "7wyDQQSzEQu8",
        "colab": {}
      },
      "source": [
        "new_prediction.head()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "bf8I1uqcEQvD"
      },
      "source": [
        "Notice that the results of `unseen_predictions` and `new_prediction` are identical."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "_HeOs8BhEQvF"
      },
      "source": [
        "# 16.0 Wrap-up / Next Steps?"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "VqG1NnwXEQvK"
      },
      "source": [
        "This tutorial has covered the entire machine learning pipeline from data ingestion, pre-processing, training the model, hyperparameter tuning, prediction and saving the model for later use. We have completed all of these steps in less than 10 commands which are naturally constructed and very intuitive to remember such as `create_model()`, `tune_model()`, `compare_models()`. Re-creating the entire experiment without PyCaret would have taken well over 100 lines of code in most libraries.\n",
        "\n",
        "We have only covered the basics of `pycaret.classification`. In following tutorials we will go deeper into advanced pre-processing, ensembling, generalized stacking and other techniques that allow you to fully customize your machine learning pipeline and are must know for any data scientist.\n",
        "\n",
        "See you at the next tutorial. Follow the link to __[Binary Classification Tutorial (CLF102) - Intermediate Level](https://github.com/pycaret/pycaret/blob/master/Tutorials/Binary%20Classification%20Tutorial%20Level%20Intermediate%20-%20CLF102.ipynb)__"
      ]
    }
  ]
}